package com.xf.lastmall.repository;


import com.xf.lastmall.moudle.entity.OrderMainEntity;
import jakarta.transaction.Transactional;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.Date;


@Repository
public interface OrderMainRepository extends JpaRepository<OrderMainEntity, String> {

    OrderMainEntity findByIdAndOrderNo(String orderId, String orderNo);

    OrderMainEntity findByOrderNo(String orderNo);

    @Transactional
    @Modifying
    @Query( value = "UPDATE tb_order_main " +
            "SET status_ = :updateStatus,update_time_ = :date " +
            "WHERE order_no_ = :orderNo AND status_ = :status", nativeQuery = true)
    int updateOrderStatus(@Param("updateStatus") String updateStatus, @Param("status") String status, @Param("date") Date date, @Param("orderNo") String orderNo);

    @Transactional
    @Modifying
    void deleteByOrderNo(String orderNo);
}
